package controller

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"mbti/model"
)

//登录管理员 因不提供管理员注册 只能更改admin表添加
func LoginAdmin(ctx *gin.Context)  {
	name:=ctx.PostForm("adminName")
	password:=ctx.PostForm("password")
	fmt.Println(name)
	if len(name)<1{
		ctx.JSON(422,gin.H{
			"code":422,
			"msg":"提交的数据有问题",
		})
		return
	}


	id,dbName,dbPassword:=model.GetExistAdmin(name)
	fmt.Println(id,dbName,dbPassword,name,password,":id,name,pss")


	if dbName !=name ||dbPassword!=password {
		ctx.JSON(422,gin.H{
			"code":422,
			"msg":"账号或密码错误",
		})
		return
	}

	ctx.JSON(200,gin.H{
		"code":200,
		"msg":"登陆成功",
	})
}

//学生登陆  若学号不存在则注册并登录  若学号存在但输入有误则无法登录
func LoginStudent(ctx *gin.Context)  {
	class:=ctx.PostForm("studentClass")
	specialize:=ctx.PostForm("specialize")
	college:=ctx.PostForm("college")
	name:=ctx.PostForm("studentName")
	studentID:=ctx.PostForm("studentID")

	fmt.Println(name)
	isOk:=model.GetExistStudent(studentID,name,college,specialize,class)
	if isOk == false {
		ctx.JSON(422,gin.H{
			"code":422,
			"msg":"账号或密码错误",
		})
		return
	}

	ctx.JSON(200,gin.H{
		"code":200,
		"msg":"登陆成功",
	})
}
